
/*************************************************
This program preps our graduate data, using all
eligible systems, and appends them together.

Here, I do not restrict the PIKs - I do that 
after the merge to earnings
*************************************************/

%macro grad_readin ; 

/* first step, append all of them together */

/********************************************
 The source of these files is the /grads/ 
   process on the production machine,
   which are brought over for this process 
*********************************************/
%let systems = utsys cdhe suny cuny psu odhe thecb mnohe usg schev mdhe; 
    
%macro ui_state;
    if system in ('utsys','thecb') then ui_state = '48' ;
    else if system = 'cdhe' then ui_state = '08';
    else if system in ('cuny','suny') then ui_state = '36' ;
    else if system = 'psu' then ui_state = '42' ;
    else if system = 'odhe' then ui_state = '39' ;
    else if system ='schev' then ui_state = '51' ;
    else if system ='ushe' then ui_state = '49';
    else if system ='mnohe' then ui_state = '27' ;
    else if system ='usg' then ui_state ='13';
    else if system ='mdhe' then ui_state='29';
%mend ui_state;

   %do jj = 1 %to %sysfunc(countw("&systems.", ' ')) ; 
        %let currsys=%scan(&systems.,&jj.) ;
        proc contents data=GRADS.grads_us_&currsys.;
	run;
    %end;


data OUTPUTS.grads_appended (drop=cohort_length degcip_2010 system grad_cohort ) ;
    set 
    %do jj = 1 %to %sysfunc(countw("&systems.", ' ')) ; 
        %let currsys=%scan(&systems.,&jj.) ;
        GRADS.grads_us_&currsys.
    %end;
    ;
    by pik ; 
    %ui_state;
    if pik not in ([ineligible piks]) ;
    if year_grad >= 2001 ; 
    if opeid not in ([ineligible opeids]) ;
run;

proc freq data=OUTPUTS.grads_appended ; 
    title 'UI STATE' ;
    tables ui_state ui_state*deglevl_code opeid  ;
run;
    
/**********************************************
    Merging in demographics from the Individual Characteristics File
	https://lehd.ces.census.gov/data/lehd-snapshot-doc/latest/sections/person_level/icf.html
**********************************************/
        
proc sort data=OUTPUTS.grads_appended nodupkey ;
        by pik opeid deglevl_code degcip year_grad ;
run;
   
data icf (keep=pik dob male race white black asian hispanic
              pob us_native ethnicity)/view=icf ;
    set ICF.icf_us ;
    male = (sex = 'M') ;
    white = race='1' ;
    black = race = '2' ;
    asian = race = '3' ;
    us_native = (pob = 'A');
    hispanic = (ethnicity='H') ;
run;

data OUTPUTS.grads_demog ; 
    merge OUTPUTS.grads_appended (in=a) icf (in=b) ;
    by pik ; 
    
    if a;
    if pik not in ([ineligible piks]) ;
run;
    
proc sort data=OUTPUTS.grads_demog out=OUTPUTS.grad_piklist  (keep=pik); 
    by pik ; 
run;
    
%mend grad_readin;
%grad_readin;
